Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(py): Fix array/list value serialization #1827

Merged
merged 1 commit into from
Dec 20, 2024

Conversation

aborgna-q
Copy link
Collaborator

The rust-side serialization definition for custom constants is a bit more complex than what we had written on the python side for array and list values.

This fixes #1826, and was tested by running the issue's example from guppy.

  • Why aren't we testing this locally?

    Constant value deserialization is a "best effort" thing.
    If we can match the serialized thing with one of the hardcoded implementors of CustomConst (registered in a global var by typetag) then we deserialize into the specific class.
    If we cannot deserialize into any specific class, we use CustomSerialized by default.

    So even if we build a constant from python and validate using the rust checker, the deserialization will succeed and validate correctly.

    It'd be nice to fail the deserialization if a constant claims to be of some specific kind but cannot be deserialized into it. I'll open an issue and look a bit into it.

@aborgna-q aborgna-q requested a review from ss2165 December 20, 2024 12:20
@aborgna-q aborgna-q requested a review from a team as a code owner December 20, 2024 12:20
@aborgna-q
Copy link
Collaborator Author

Will hugr-model redefine constant serialization? I didn't find references to that after a quick search

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 86.63%. Comparing base (b7b2bcd) to head (1aa5619).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
hugr-py/src/hugr/std/collections/array.py 25.00% 3 Missing ⚠️
hugr-py/src/hugr/std/collections/list.py 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1827      +/-   ##
==========================================
- Coverage   86.64%   86.63%   -0.01%     
==========================================
  Files         192      192              
  Lines       34754    34758       +4     
  Branches    31571    31571              
==========================================
  Hits        30113    30113              
- Misses       2940     2944       +4     
  Partials     1701     1701              
Flag Coverage Δ
python 92.31% <25.00%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this!

model will change constant serialization, to become static "recipes" for constructing runtime values. There is some discussion here: #1425.

@@ -60,7 +60,7 @@ class ArrayVal(val.ExtensionValue):
"""Constant value for a statically sized array of elements."""

v: list[val.Value]
ty: tys.Type
ty: Array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is non-breaking because Array satisfies the Type protocol, correct?

Copy link
Collaborator Author

@aborgna-q aborgna-q Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine for reading since it's a type refinement.

For writing into the variable it is actually a breaking change. I assumed the dataclass was frozen, but it seems it's not.

Anyways I'd say mutating the attribute directly is not common (since the type is normally constructed using its custom __init__), and putting in a non-array type should be a bug anyways.

@ss2165
Copy link
Member

ss2165 commented Dec 20, 2024

@aborgna-q aborgna-q added this pull request to the merge queue Dec 20, 2024
Merged via the queue into main with commit 7bf85b9 Dec 20, 2024
22 of 23 checks passed
@aborgna-q aborgna-q deleted the ab/fix-array-list-val-serialize branch December 20, 2024 12:45
github-merge-queue bot pushed a commit that referenced this pull request Dec 20, 2024
🤖 I have created a release *beep* *boop*
---


##
[0.10.2](hugr-py-v0.10.1...hugr-py-v0.10.2)
(2024-12-20)


### Features

* Add `StringVal` to hugr-py
([#1818](#1818))
([b05a419](b05a419))


### Bug Fixes

* **py:** Fix array/list value serialization
([#1827](#1827))
([7bf85b9](7bf85b9))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: Seyon Sivarajah <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ArrayValue created by hugr-py cannot be resolved by hugr-rs
2 participants